﻿namespace AuSys.Utils.Reflection
{
    public static class PropCheckHelper
    {
        public static bool AllStringPropertiesNotEmpty<T>(
            T obj, out string? emptyPropName, List<string>? skipCheckProps = null)
        {
            if (obj is null)
            {
                emptyPropName = null;
                return false;
            }
            var properties = typeof(T).GetProperties();
            foreach (var property in properties)
            {
                if(skipCheckProps?.Contains(property.Name) ?? false)
                    continue;
                if (property.PropertyType == typeof(string))
                {
                    var value = property.GetValue(obj) as string;

                    if (string.IsNullOrWhiteSpace(value))
                    {
                        emptyPropName = property.Name;
                        return false;
                    }
                }
            }
            emptyPropName = null;
            return true;
        }
    }
}
